package me.xiaoyan.android.widget;

import java.util.HashMap;
import java.util.Map;

import android.os.Handler;

public class StaticData {
	private Handler handler = null;
	private Map<String, Object> dataMap = new HashMap<String, Object>();
	private static StaticData obj = null;

	private StaticData() {
	}

	public static StaticData getInstance() {
		if (null == obj) {
			obj = new StaticData();
		}
		return obj;
	}

	public void setHandler(Handler handler) {
		if (null == this.handler) {
			this.handler = handler;
		}
	}

	public Handler getHandler() {
		return handler;
	}

	public void putData(String key, Object value) {
		if (null != value && null != key) {
			this.dataMap.put(key, value);
		}
	}

	@SuppressWarnings("unchecked")
	public <T> T getData(String key, T t) {
		if (null != key) {
			Object value = this.dataMap.get(key);
			if (null != value) {
				return (T) value;
			}
		}
		return null;
	}

	public Object getData(String key) {
		return this.dataMap.get(key);
	}

	public int getInt(String key) {
		Object data = this.dataMap.get(key);
		return data == null ? 0 : Integer.parseInt(data.toString());
	}
}
